/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.kramerius.fedoraaccess;

import cz.mzk.kramerius.commons.DatastreamId;
import cz.mzk.kramerius.fedoraaccess.exception.DatastreamNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;
import org.dom4j.Document;

/**
 *
 * @author Martin Řehánek <rehan at mzk.cz>
 */
public interface FedoraConnector {

    /**
     * Creates relation (in rels-ext) of type 
     * <hasModel xmlns="info:fedora/fedora-system:def/model#" rdf:resource="info:fedora/model:page"/>
     * @param subject
     * @param relationship
     * @param relationshipNsPrefix Namespace prefix of relationship as defined
     * in package cz.mzk.rehan.commons.Namespaces
     * @param object object (in Fedora) of relationship
     * @return
     */
    boolean addRelationship(String subject, String relationship, String relationshipNsPrefix, String object);
    
//    /**
//     * Creates relation (in rels-ext) of type 
//     * <tiles-url xmlns="http://www.nsdl.org/ontologies/relationships#">imageserver.mzk.cz/mzk03/001/050/692/2619298376/1050692_00001</tiles-url>
//     * @param subject
//     * @param relationship
//     * @param relationshipNsPrefix Namespace prefix of relationship as defined
//     * in package cz.mzk.rehan.commons.Namespaces
//     * @param value value of relationship
//     * @return
//     */
//    boolean addGeneralRelation(String subject, String relationship, String relationshipNsPrefix, String value);

    /**
     * Searches for object according to the terms appearing in object metadata
     *
     * @param termsString the terms or conditions for the search
     * @return List of pids
     */
    List<String> findObjects(String termsString);

    /**
     * Creates Document containing given inline xml datastream content of
     * digital object
     *
     * @param pid PID of digital object
     * @param dsId id of datastream
     * @return
     */
    Document getXmlDatastreamDissemination(String pid, DatastreamId dsId);

    /**
     * Imports foxml into Fedora repository
     *
     * @param foxmlDoc document with foxml to import
     * @return PID of imported digital object
     */
    String importFoxml(Document foxmlDoc, String logMessage);

    /**
     * Searches for an object and returns true if it exists
     *
     * @param objectPid PID of the object
     * @return true if there is such an object in Fedora repository
     */
    boolean objectExists(String objectPid);

    /**
     * Prints summary about the Fedora repository instance to the stdout
     */
    void printRepositoryInfo();

    /**
     * Prints summary about the Fedora repository instance to the PrintStream
     *
     * @param out
     */
    void printRepositoryInfo(PrintStream out);

    /**
     * Removes digital object from Fedora repository
     *
     * @param pid object's PID
     * @param logMessage
     */
    void removeObject(String pid, String logMessage);

    boolean removeRelationship(String subject, String relationship, String relationshipNsPrefix, String object);

    boolean removeRelationships(String subject, String relationship, String relationshipNsPrefix);

    boolean updateDatastreamInlineContent(String pid, DatastreamId dsId, Document content);

    String getRepositoryUrl();

    Document getObjectFoxml(String pid);

    boolean purgeDatastream(String pid, DatastreamId dsId, String logMessage);

    boolean addExternallyReferencedDatastream(String pid, DatastreamId dsId, String url, String mimeType, String label);
    
    boolean addManagedDatastreamByUrl(String pid, DatastreamId dsId, String url, String mimeType, String label);
    
    Document getDatastreamAsXml(String pid, DatastreamId dsId) throws DatastreamNotFoundException, IOException;
}
